<template>
  <view>
    <view>
      <slot name="top"></slot>
    </view>
        <view
      class="ss-order-card-warp ss-flex ss-col-stretch ss-row-between bg-white"
      :style="[{ borderRadius: radius + 'rpx', marginBottom: marginBottom + 'rpx' }]"
      @click="handleClick"
    >
      <view class="img-box ss-m-r-24">
        <image class="order-img" :src="sheep.$url.cdn(img)" mode="aspectFill"></image>
      </view>
      <view
        class="box-right ss-flex-col ss-row-between"
        :style="[{ width: titleWidth ? titleWidth + 'rpx' : '' }]"
      >
        <view class="title-text ss-line-2" v-if="title">{{ title }}</view>
        <!-- 微豆和尺码在同一行显示 -->
        <view v-if="props.microbean || skuString" class="microbean-sku-row ss-m-t-8 ss-m-b-12">
          <view class="microbean-box" v-if="props.microbean">
            <image mode="widthFix" :src="state.goldenBean" class="goldenBean-img"></image>
            {{props.microbean}}
          </view>
          <view v-if="skuString" class="spec-text">{{ skuString }}</view>
        </view>
        <view class="groupon-box">
          <slot name="groupon"></slot>
        </view>
        <view class="price-microbean-container ss-flex ss-col-center ss-row-between">
          <!-- 价格在右边 -->
          <view class="price-container ss-flex ss-col-center">
            <!-- 当前价格 -->
            <view
              class="price-text ss-flex ss-col-center"
              :style="[{ color: priceColor }]"
              v-if="price !== '' && price !== null && price !== undefined"
            >
              <text class="price-text-wrap">￥{{ price }}</text> 
            </view>
            
            <!-- 原价显示 -->
            <view
              v-if="originalPrice && originalPrice !== '' && originalPrice !== null && originalPrice !== undefined"
              class="original-price-text"
            >
              ￥{{ originalPrice }}
            </view>
            
            <view v-if="score && Number(price) > 0">+</view>
            <view class="price-text ss-flex ss-col-center" v-if="score">
              <image
                :src="sheep.$url.static('/assets/addons/shopro/uniapp/goods/score1.svg')"
                class="score-img"
              ></image>
              <view>{{ score }}</view>
            </view>
            
            <view v-if="num" class="total-text ss-flex ss-col-center">x {{ num }}</view>
            <slot name="priceSuffix"></slot>
          </view>
        </view>
        <view class="tool-box">
          <slot name="tool"></slot>
        </view>
        <view>
          <slot name="rightBottom"></slot>
        </view>
      </view>
    </view>
  </view>
</template>

<script setup>
  import sheep from '@/sheep';
  import { computed,reactive} from 'vue';
  const state=reactive({
	  goldenBean: 'https://wemayshiguang.oss-cn-shanghai.aliyuncs.com/goldenBean.png',
  })
  /**
   * 订单卡片
   *
   * @property {String} img 											- 图片
   * @property {String} title 										- 标题
   * @property {Number} titleWidth = 0								- 标题宽度，默认0，单位rpx
   * @property {String} skuText 										- 规格
   * @property {String | Number} price 								- 价格
   * @property {String} priceColor 									- 价格颜色
   * @property {Number | String} num									- 数量
   *
   */
  const props = defineProps({
    img: {
      type: String,
      default:'',
    },
    title: {
      type: String,
      default: '这是商品标题这是商品标题这是商品标题这是商品标题这是商品标题',
    },
    titleWidth: {
      type: Number,
      default: 0,
    },
    skuText: {
      type: [String, Array],
      default: '',
    },
    price: {
      type: [String, Number],
      default: '',
    },
    priceColor: {
      type: [String],
      default: '',
    },
    num: {
      type: [String, Number],
      default: 0,
    },
    score: {
      type: [String, Number],
      default: '',
    },
    radius: {
      type: [String],
      default: '',
    },
    marginBottom: {
      type: [String],
      default: '',
    },
	microbean:{
		type: [String, Number],
		default: '',
	},
	originalPrice: {
		type: [String, Number],
		default: '',
	}
  });
  const skuString = computed(() => {
    if (!props.skuText) {
      return '';
    }
    if (typeof props.skuText === 'object') {
      return props.skuText.join(',');
    }
    return props.skuText;
  });

  // 定义点击事件
  const emit = defineEmits(['click']);
  
  // 处理点击事件
  const handleClick = () => {
    emit('click');
  };
</script>

<style lang="scss" scoped>
  .score-img {
    width: 36rpx;
    height: 36rpx;
    margin: 0 2rpx;
  }
  .price-microbean-container {
    width: 100%;
    margin-top: 8rpx;
    gap: 12rpx;
  }
  
  .microbean-sku-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
  }
  
  .microbean-box{
    display: flex;
    align-items: center;
  }
  
  .price-container {
    display: flex;
    align-items: center;
    gap: 6rpx;
  }
  .price-text-wrap{
    font-size: 24rpx;
    font-weight: 500;
  }
  .goldenBean-img{
	  width:20rpx;
	  height:20rpx;
	  margin-right:10rpx;
  }
  
  .original-price-text {
    font-size: 20rpx;
    color: #a0a0a0;
    text-decoration: line-through;
    margin-left: 12rpx;
  }
  .ss-order-card-warp {
    padding: 20rpx;

    .img-box {
      width: 164rpx;
      height: 164rpx;
      border-radius: 10rpx;
      overflow: hidden;

      .order-img {
        width: 164rpx;
        height: 164rpx;
      }
    }

    .box-right {
      flex: 1;
      // width: 500rpx;
      // height: 164rpx;
      position: relative;

      .tool-box {
        position: absolute;
        right: 0rpx;
        bottom: 0rpx;
      }
    }

    .title-text {
      font-size: 26rpx;
      font-weight: 500;
      line-height: 36rpx;
    }

    .spec-text {
      font-size: 22rpx;
      font-weight: 400;
      color: $dark-9;
      min-width: 0;
      overflow: hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-line-clamp: 1;
      -webkit-box-orient: vertical;
    }

    .price-text {
      font-size: 24rpx;
      font-weight: 500;
      font-family: OPPOSANS;
    }

    .total-text {
      font-size: 22rpx;
      font-weight: 400;
      line-height: 22rpx;
      color: $dark-9;
      margin-left: 8rpx;
    }
  }
 
</style>
